import matplotlib.pyplot as plt
import seaborn as sns
import math
import numpy as np
import matplotlib
matplotlib.rcParams.update({'font.size': 18})

def cdf(fn, div='init', filter=''):
    x = []
    found = False
    for line in open('bgp-down.log'):
        if found:
            if '=' in line:
                break
            arr = line.split(',')
            if '11.0.0.1' in line:
                x.append(float(arr[1]))
        if found == False and 'down' in line:
            found = True
            
    print('#updates: %s' % len(x))
    print(x[-1]-x[0])

    x1 = []
    found = False
    for line in open('bgp-up.log'):
        if found:
            if '=' in line:
                break
            arr = line.split(',')
            if '11.0.0.3' in line:
                x1.append(float(arr[1]))
        if found == False and 'up' in line:
            found = True
            
    print('#updates: %s' % len(x1))
    print(x1[-1]-x1[0])
    if (len(x) == 0):
        return
    y = [d - x[0] for d in x]
    y1 = [d - x1[0] for d in x1]

    sns.ecdfplot(data=y, label='Link A-Internet fail')
    sns.ecdfplot(data=y1, label='Set up link B-C')
    plt.legend()
    plt.xlabel('Time(s)')
    plt.grid()
    plt.tight_layout()
    plt.show()

cdf(1)